﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using KVB.Common;

namespace Customer_Profile.SuperUpdate.DBDao
{
    public class SupserDao
    {
        public static DataSet getDealInfo(string deal_no)          //搜索Deals
        {
            string strSQL = "SELECT card_no,cp.cparty_name,prod_code,due_prodcode,due_prodremark,md.entity,initial_amount,due_amount,should_amount ,stand_discount,real_discount,amount_spread,";
            strSQL += " value_date,due_date,Convert(varchar(10),review_date,120) review_date,dealer,md.designee ";
                   strSQL+=" FROM dbo.mmdeals md INNER JOIN dbo.cparty cp  ";
                   strSQL += " ON md.cparty_id = cp.cparty_id ";
                   strSQL+=" WHERE md.deal_no='"+deal_no+"'";
            
            DataSet ds = null;
            SqlConnection conn = null;
            try
            {
                DB.Connection(ref conn);
                ds = DB.ExecuteDataset(conn, CommandType.Text, strSQL);
            }
            catch (Exception e)
            {
                KVB.Common.Log.WriteDefaultLog("SupserDao.getDealInfo", e.Message + "SQL:" + strSQL);
                throw e;
            }
            finally
            {
                DB.ConnDispose(ref conn);
            }
            return ds;
        }

        public static bool UpdateDeal(string deal_no,
            string prod_code,
            string due_prodcode,
            string due_prodremark,

            string should_amount,
            string stand_discount,
            string real_discount,
            string amount_spread,
            string due_amount,

            string value_date,
            string due_date,
            string review_date,
            string dealer,
            string designee)          //搜索Deals
        {
            bool bok = false;

            string strSQL = "UPDATE dbo.mmdeals ";
            strSQL += " SET prod_code ='" + prod_code + "', ";
            strSQL += " due_prodcode ='" + due_prodcode + "', ";
            strSQL += " due_prodremark ='" + due_prodremark + "', ";

            strSQL += " should_amount ='" + should_amount + "', ";
            strSQL += " stand_discount ='" + stand_discount + "', ";
            strSQL += " real_discount ='" + real_discount + "', ";
            strSQL += " amount_spread ='" + amount_spread + "', ";
            strSQL += " due_amount ='" + due_amount + "', ";

            strSQL += " value_date ='" + value_date + "', ";
            strSQL += " due_date ='" + due_date + "', ";
            strSQL += " review_date ='" + review_date + "', ";
            strSQL += " dealer ='" + dealer + "', ";
            strSQL += " designee='" + designee + "'";
            strSQL += " WHERE deal_no='" + deal_no+"'";

            SqlConnection conn = null;
            try
            {
                DB.Connection(ref conn);
                DB.ExecuteNonQuery(conn, CommandType.Text, strSQL);
                bok = true;
            }
            catch (Exception e)
            {
                KVB.Common.Log.WriteDefaultLog("SupserDao.getDealInfo", e.Message + "SQL:" + strSQL);
                bok = false;
                throw e;
            }
            finally
            {
                DB.ConnDispose(ref conn);
            }
            return bok;
        }
    }
}